package org.domain.sigepac.repository.impl;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.domain.sigepac.Entity.Aluno;
import org.domain.sigepac.repository.RepositorioAluno;
import org.domain.sigepac.repository.RepositorioGenerico;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;



/**
 * @author bruno.canto
 */
@Name("repositorioAluno")
@AutoCreate
public class RepositorioAlunoImpl extends RepositorioGenerico<Aluno>
    implements RepositorioAluno {



	@SuppressWarnings("unchecked")
	public List<Aluno> pesquisarPorNome(String nome) {
		try {
			return (List<Aluno>) this.entityManager.createQuery(
					"from Aluno as aluno where upper(aluno.nome) like ?")
					.setParameter(1,"%"+nome.toUpperCase()+"%").getResultList();

		} catch (Exception e) {
			return Collections.EMPTY_LIST;
		}
	}

	public List<Aluno> pesquisarPorPeriodo(Date inicio, Date fim) {
		Criteria criteria= getSession().createCriteria(Aluno.class);

		criteria.add(Restrictions.between("dataInscricao", inicio, fim));
		return criteria.list();
	}

	@Override
	public List<Aluno> listar() {
		return super.listar(Order.asc("nome"));
	}

}
